import * as THREE from 'three'
import { WeatherPoints } from './weatherPoints'

export class Rain{
  constructor(scene){
    this.points = new WeatherPoints(scene,{
      size: 20,
      opacity: 0.4,
      range: 1000,
      count: 800,
      setAnimation(position) {
        position.y -= position.speedY;

        // 边界检查
        if (position.y <= 0) {
          position.y = this.range / 2;
        }
      },
      setPosition(position) {
        position.speedY = 20
      },
      url: '../../src/assets/rain.png',
    })
    // this.scene = scene

    // // 范围
    // this.range = 1000
    // // 个数
    // this.count = 800
    // this.pointList = []

    // this.init()
  }
  init(){
    this.material = new THREE.PointsMaterial({
      size:20,
      map:new THREE.TextureLoader().load('../../src/assets/rain.png'),
      transparent:true,
      opacity:0.4,
      depthTest:false,
    })
    this.geometry = new THREE.BufferGeometry()
    for (let i = 0; i < this.count; i++) {
      const position  = new THREE.Vector3(
        Math.random() * this.range - this.range / 2 ,
        Math.random() * this.range,
        Math.random() * this.range - this.range / 2
      )
        position.speedY = 20
      this.pointList.push(position)
    }
    this.geometry.setFromPoints(this.pointList)
    this.points = new THREE.Points(this.geometry,this.material)
    this.scene.add(this.points)
  }
  animation(){
    this.points.animation();
  }
}